import { Directive, ElementRef, HostListener } from '@angular/core';

@Directive({
  selector: '[libTrimOnInput]',
  standalone: true
})
export class TrimOnInputDirective {

  constructor(
    private el: ElementRef
  ) { }

  @HostListener('input', ['$event']) onInput(event: Event) {
    const input = event.target as HTMLInputElement;
    input.value = input.value.trim();
    this.el.nativeElement.value = input.value;
  }

}
